package com.eurekaclient.service.impl;

import com.eurekaclient.entity.StudentEntity;
import com.eurekaclient.service.StudentService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@Service
public class StudentServiceImpl  implements StudentService {
    private static Map<Long,StudentEntity> studentEntityMap;
    static{
        studentEntityMap=new HashMap<>();
        studentEntityMap.put(1L,new StudentEntity(1L,"张三",22));
        studentEntityMap.put(2L,new StudentEntity(2L,"李四",27));
        studentEntityMap.put(3L,new StudentEntity(3L,"王五",30));

    }

    @Override
    public Collection<StudentEntity> findAll() {
        return studentEntityMap.values();
    }

    @Override
    public StudentEntity findById(Long id) {
        return studentEntityMap.get(id);
    }

    @Override
    public void saveOrUpdate(StudentEntity studentEntity) {
        studentEntityMap.put(studentEntity.getId(),studentEntity);
    }

    @Override
    public void del(Long id) {
        studentEntityMap.remove(id);
    }
}
